﻿#region File Description
/*-----------------------------------------------------------------------------
 Author: Jose Antonio Gallego
 Date: 24/10/2011
 
 License: Ms-PL
 
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 SOFTWARE.

 The example companies, organizations, products, domain names,
 e-mail addresses, logos, people, places, and events depicted
 herein are fictitious.  No association with any real company,
 organization, product, domain name, email address, logo, person,
 places, or events is intended or should be inferred.
-----------------------------------------------------------------------------*/
#endregion

using System;
using System.ComponentModel;
using System.Linq;
using Microsoft.Phone.Controls;
using Zombsquare.Helpers;
using Zombsquare.Models;

namespace Zombsquare.Pages.Guia
{
    public partial class GuiaPage : PhoneApplicationPage, INotifyPropertyChanged
    {
        private guia _guia;
        int indexGuia = 0;

        public GuiaPage()
        {
            InitializeComponent();
            LoadGuia();
            DataContext = this;
        }

        /// <summary>
        /// Carga la información de la guia, vamos las preguntas
        /// </summary>
        private void LoadGuia()
        {
            Storage.CopyFileToSotrage("Resources/Library/Guia.xml", "Guia.xml");

            _guia = Storage.LoadSetting<guia>("Guia.xml");

            indexGuia = 0;

            ActualizarGuia();
        }

        private void ActualizarGuia()
        {
            Titulo = _guia.fichas[indexGuia].titulo;
            Texto = _guia.fichas[indexGuia].texto;
        }

        private string _titulo;
        public string Titulo
        {
            get
            {
                return _titulo;
            }
            set
            {
                _titulo = value;
                NotifyPropertyChanged("Titulo");
            }
        }

        private string _texto;
        public string Texto
        {
            get
            {
                return _texto;
            }
            set
            {
                _texto = value;
                NotifyPropertyChanged("Texto");
            }
        }

        #region Property Changed

        private void NotifyPropertyChanged(string propertyName)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        public event PropertyChangedEventHandler PropertyChanged = delegate { };

        #endregion

        private void ApplicationBarIconButton_Click(object sender, EventArgs e)
        {
            indexGuia--;
            if (indexGuia < 0)
                indexGuia = 0;

            ActualizarGuia(); 
        }

        private void ApplicationBarIconButton_Click_1(object sender, EventArgs e)
        {
            indexGuia++;
            if (indexGuia > _guia.fichas.Count() - 1)
                indexGuia = _guia.fichas.Count() - 1;

            ActualizarGuia();    
        }
    }
}